<?php
    //include_once 'init.php';
        if(!empty($_POST)){
             if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){
                $id=$_POST['id'];
                $val=$_POST['val'];
                $filed=$_POST['filed'];
                $edit_time=time();//修改时间
               $sql="update `news` set `$filed`='$val',`edit_time`=$edit_time where `id`=$id";
                mysqli_query($link,$sql);
                echo $res=mysqli_affected_rows($link);
                die;
        }
            $id=$_POST['id'];//id
            $title=$_POST['title'];//标题
            $cate_id=$_POST['cate_id'];//类型
            $author=$_POST['author'];//作者
            $content=$_POST['content'];//内容
            $send_user=$_SESSION['admin']['username'];//发布人
            $edit_time=time();//修改时间

            $data['id']=$id;
            $data['title']=$title;
            $data['cate_id']=$cate_id;
            $data['author']=$author;
            $data['content']=$content;
            $data['send_user']=$send_user;
            $data['edit_time']=$edit_time;
           $result= edit($c,$id,$data);
                if($result>0){
                    echo '<script>alert("新闻修改成功");location.href="index.php?c=news&a=list&admin=1";</script>';die;
                }else{
                    echo '<script>alert("新闻修改失败");history.go(-1);</script>';die;
                }
        }
        $id=$_GET['id'];
        $where['id']=$id;
        $data =getSelectOne($c,$where);

    include(VIEW_PATH.$admin.'layout.html');

?>